#pragma rtGlobals=1 // Use modern global access method. #include //2006.09.22 renew menu "ImageLength" "1: Read Picture files", typepanelopen() "2: Show operation panels", sousapanelopen();infopanelopen() "3: Show a histgram figure", hisutoguramu() end ///////////////////////////////////////// ////Calculate a length from picture image function naosu(ctrname) :buttoncontrol string ctrname nvar mag mag=1 setaxis/a/r left setaxis/a top end function kakudai(ctrname) :buttoncontrol string ctrname nvar mag variable haba, takasa, posi1, posi2, posi3, posi4, hcenter, vcenter if(strlen(csrwave(a))==0) doalert 0, "No cursor A on the top picture." return 0 elseif(strlen(csrwave(b))==0) hcenter=hcsr(a) vcenter=vcsr(a) else hcenter=(hcsr(a)+hcsr(b))/2 vcenter=(vcsr(a)+vcsr(b))/2 endif mag=mag+1 haba=dimsize(csrwaveref(a),0)/mag takasa=dimsize(csrwaveref(a),1)/mag posi1=hcenter-(haba/2) posi2=hcenter+(haba/2) posi3=vcenter-(takasa/2) posi4=vcenter+(takasa/2) SetAxis top posi1, posi2 setaxis/r left posi4, posi3 end function linekaki(ctrname) : ButtonControl string ctrname variable px1,px2,py1,py2 if(!waveexists(csrwaveref(A)) || !waveexists(csrwaveref(B)) ) doalert 0, "No cursors on the top picture." return 0 endif px1=hcsr(a) px2=hcsr(b) py1=vcsr(a) py2=vcsr(b) string tempwindow=gettargetgraph() print tempwindow SetDrawEnv/w=$tempwindow arrow=3, linefgc=(65500,0,0), linethick=1.2, xcoord=top, ycoord=left, arrowlen=2.00, arrowfat=2 DrawLine/w=$tempwindow px1, py1, px2, py2 end function henkou(ctrname) : buttoncontrol string ctrname variable xx,yy nvar px2nm, pxls variable delta if(!waveexists(csrwaveref(A)) || !waveexists(csrwaveref(B)) ) delta=1 else variable px1=hcsr(a) variable px2=hcsr(b) variable py1=vcsr(a) variable py2=vcsr(b) delta=sqrt((px1-px2)^2+(py1-py2)^2) endif xx=0 yy=pxls prompt delta, "Set the length of scale bar (pxels)." prompt xx, "Set the value of scale bar (a.u.). Caution the unit." prompt yy, "scale value. No change usually. If tag positions is not correct. " doprompt "Do it", delta, xx, yy if(V_flag) return -1 endif px2nm=xx/delta pxls=yy end function savepic(ctrname) :buttoncontrol string ctrname string wname wname=gettargetgraph() SavePICT/o/P=fpath/E=-5/b=72 dowindow/B $wname doalert 0, "This picture is saved on the folder you choosed." end function calcdis(ctrname) :buttoncontrol string ctrname string tagname variable px1, px2, py1, py2, delta nvar px2nm, tagnum, pxls, yarinaosu, diamnum wave Length, PixelLength wave/t Point1, Point2, TagNO if(!waveexists(csrwaveref(A)) || !waveexists(csrwaveref(B)) ) doalert 0, "No cursor on the top picture." return 0 endif px1=hcsr(a) px2=hcsr(b) py1=vcsr(a) py2=vcsr(b) delta=sqrt((px1-px2)^2+(py1-py2)^2) diamnum=delta tagname="Tag"+ num2str(tagnum) Tag/c/n=$tagname $csrwave(a), (px1+py1*pxls), "No."+num2str(tagnum) TagNO[tagnum]="No." + num2str(tagnum) Length[tagnum]=delta*px2nm PixelLength[tagnum]=delta Point1[tagnum]="(" + num2str(px1) + ", " + num2str(py1) + ")" Point2[tagnum]="(" + num2str(px2) + ", " + num2str(py2) + ")" yarinaosu=yarinaosu+1 tagnum=tagnum+1 end function yarinaosi(ctrname) :ButtonControl string ctrname nvar tagnum, yarinaosu wave/t TagNO, Point1, Point2 wave Length, PixelLength string tagname if(yarinaosu==0) doalert 0, "It is impossible to un-do any more." return 0 endif tagnum=tagnum-1 tagname="tag"+ num2str(tagnum) PixelLength[tagnum]=0 TagNO[tagnum]="" Length[tagnum]=0 Point1[tagnum]="" Point2[tagnum]="" tag/k/n=$tagname yarinaosu=yarinaosu-1 end function/s gettargetgraph() string upimagelist=imagenamelist("",";") string upimage=upimagelist[0,strsearch(upimagelist,";",0)-1] nvar pictnum pictnum=str2num(upimage[strsearch(upimage,"_",0)+1,strlen(upimage)-1]) return upimage + "_" end proc sousapanelopen() dowindow/k sousapanel newpanel/w=(800,100,950,380) dowindow/c/t sousapanel, "Operation" DrawText 11,26,"Operation" SetDrawEnv fillfgc= (52224,52224,52224),fillpat= 1 drawrect 9,29,142,220 Button DL, size={100, 30},pos={24,40},title="Draw a line",proc = linekaki Button torikomi, size={100, 30},pos={24,80},title="Calc Length",proc = calcdis Button kakudaisuru, size={40, 30},pos={24,130},title="DOWN",proc = kakudai Button zentaihyouji, size={40, 30},pos={75,130},title="OVER",proc = naosu Button mouitido, size={65, 30},pos={24,178},title="Undo",proc = yarinaosi button b1 pos={24, 230}, size={100, 30}, title="Setting", fsize=16, proc=henkou SetDrawEnv fillpat= 0 end proc infopanelopen() dowindow/k infopanel newpanel/w=(800,500,1005,670) dowindow/c/t infopanel, "Information" SetDrawEnv fillpat= 0 drawrect 6,9,196,147 ValDisplay bairitu, size={170,30},pos={17,24},title="Length Ratio (a.u./pixel) :",value=px2nm ValDisplay gazou, size={170,30},pos={17,54},title="Horizontal length (pixels) :",value=pxls ValDisplay targetw size={170,30},pos={17,84},title="Target Window → Picture_",value=pictnum ValDisplay disview size={170,30},pos={17,114},title="Calculated Length (a.u.) :",value=diamnum end ///////////////////////////////////////////////// //Panel for choice of type of picture file function typepanelopen() dowindow/k typepanel newpanel/w=(400,200,710,270) dowindow/c/t typepanel, "Choose type of image files." button b1 pos={20, 20}, size={80, 30}, title=".BMP", fsize=16, proc=typeBMP button b2 pos={110, 20}, size={80, 30}, title=".TIF", fsize=16, proc=typeTIF button b3 pos={200, 20}, size={80, 30}, title=".JPEG", fsize=16, proc=typeJPEG end function typeBMP(ctrname) : buttoncontrol string ctrname string flist string fname, wname variable u=0, flagX=0, i=0, fsize variable/G px2nm=1.00, pxls=0, yarinaosu=0, tagnum=1, pictnum, diamnum, mag=1 dowindow/k typepanel newpath/O/M="Take me to a pictures folder !" fpath if(!V_flag==0) return 0 endif flist=IndexedFile(fpath,-1,".bmp") if(strlen(flist)==0) //go out if there is no picture file. doalert 0,"No .BMP picture file there." return 0 endif make/o/d/n=1000 Length, PixelLength make/o/t/n=1000 TagNO, Point1, Point2 edit TagNO, Length, PixelLength, Point1, Point2 u=itemsinlist(flist)-1 do fname=stringfromlist(u,flist) wname=fname[0,strsearch(fname,".",0)-1] string wname2="Picture_" + num2str(u) ImageLoad/P=fpath/T=bmp/G/n=$wname2 fname //pixelの横幅により画像の大きさを調整 if(dimsize(imagenametowaveref("", wname2),0) < 1000) fsize=1 else if(dimsize(imagenametowaveref("", wname2),0) < 2000) fsize=0.5 else if(dimsize(imagenametowaveref("", wname2),0) < 3000) fsize=0.3 else fsize=0.2 endif endif endif DoAutoSizeImage(fsize,-1) string wname3=wname2+"_" dowindow/c $wname3 SetDrawEnv xcoord=abs,ycoord=abs,textrgb=(0,65280,65280),fstyle= 1 DrawText 90,33,wname Button hozon, size={45, 25},pos={25,25},title="Next",proc = savepic showinfo u=u-1 //←次のファイルへの参照番号減少 if(u==-1) pictnum=u+1 break endif while(1) pxls=dimsize(imagenametowaveref("", wname2),0) execute "sousapanelopen()" execute "infopanelopen()" end function typeTIF(ctrname) : buttoncontrol string ctrname string flist string fname, wname variable u=0, flagX=0, i=0, fsize variable/G px2nm=1.00, pxls=0, yarinaosu=0, tagnum=1, pictnum, diamnum, mag=1 dowindow/k typepanel newpath/O/M="Take me to a pictures folder !" fpath if(!V_flag==0) return 0 endif flist=IndexedFile(fpath,-1,".tif") if(strlen(flist)==0) //go out if there is no picture file. doalert 0,"No TIFF picture file there." return 0 endif make/o/d/n=1000 Length, PixelLength make/o/t/n=1000 TagNO, Point1, Point2 edit TagNO, Length, PixelLength, Point1, Point2 u=itemsinlist(flist)-1 do fname=stringfromlist(u,flist) wname=fname[0,strsearch(fname,".",0)-1] string wname2="Picture_" + num2str(u) ImageLoad/P=fpath/T=tiff/G/n=$wname2 fname //pixelの横幅により画像の大きさを調整 if(dimsize(imagenametowaveref("", wname2),0) < 1000) fsize=1 else if(dimsize(imagenametowaveref("", wname2),0) < 2000) fsize=0.5 else if(dimsize(imagenametowaveref("", wname2),0) < 3000) fsize=0.3 else fsize=0.2 endif endif endif DoAutoSizeImage(fsize,-1) string wname3=wname2+"_" dowindow/c $wname3 SetDrawEnv xcoord=abs,ycoord=abs,textrgb=(0,65280,65280),fstyle= 1 DrawText 90,33,wname Button hozon, size={45, 25},pos={25,25},title="Next",proc = savepic showinfo u=u-1 //←次のファイルへの参照番号減少 if(u==-1) pictnum=u+1 break endif while(1) pxls=dimsize(imagenametowaveref("", wname2),0) execute "sousapanelopen()" execute "infopanelopen()" end function typeJPEG(ctrname) : buttoncontrol string ctrname string flist string fname, wname variable u=0, flagX=0, i=0, fsize variable/G px2nm=1.00, pxls=0, yarinaosu=0, tagnum=1, pictnum, diamnum, mag=1 dowindow/k typepanel newpath/O/M="Take me to a pictures folder !" fpath if(!V_flag==0) return 0 endif flist=IndexedFile(fpath,-1,".jpg") if(strlen(flist)==0) //go out if there is no picture file. doalert 0,"No .JPEG picture file there." return 0 endif make/o/d/n=1000 Length, PixelLength make/o/t/n=1000 TagNO, Point1, Point2 edit TagNO, Length, PixelLength, Point1, Point2 u=itemsinlist(flist)-1 do fname=stringfromlist(u,flist) wname=fname[0,strsearch(fname,".",0)-1] string wname2="Picture_" + num2str(u) ImageLoad/P=fpath/T=jpeg/G/n=$wname2 fname //pixelの横幅により画像の大きさを調整 if(dimsize(imagenametowaveref("", wname2),0) < 1000) fsize=1 else if(dimsize(imagenametowaveref("", wname2),0) < 2000) fsize=0.5 else if(dimsize(imagenametowaveref("", wname2),0) < 3000) fsize=0.3 else fsize=0.2 endif endif endif DoAutoSizeImage(fsize,-1) string wname3=wname2+"_" dowindow/c $wname3 SetDrawEnv xcoord=abs,ycoord=abs,textrgb=(0,65280,65280),fstyle= 1 DrawText 90,33,wname Button hozon, size={45, 25},pos={25,25},title="Next",proc = savepic showinfo u=u-1 //←次のファイルへの参照番号減少 if(u==-1) pictnum=u+1 break endif while(1) pxls=dimsize(imagenametowaveref("", wname2),0) execute "sousapanelopen()" execute "infopanelopen()" end ///////////////////////////////////////////////////////// function hisutoguramu() wave Length variable i=1, tagnum_temp nvar tagnum tagnum_temp=tagnum make/o/d Length_histgram make/o/d/n=(tagnum_temp-1) temp_hist do temp_hist[i-1]=Length[i] i=i+1 while(i